package my.myorm.tool.jdbc;

import javax.servlet.http.HttpServletRequest;

/**
 * 分页对象，从HttpServetRequest中提取页数和每页记录数
 *
 * @author Skeven Huang
 * @version 1.0
 */
public class Pages {

    private int pageSize = 20;
    private String countField = "*";
    private HttpServletRequest request = null;
    public int curPage = -1;

    /**
     * 默认每页大小为20，分页字段为*，起始页数为-1,request为null
     */
    public Pages() {
    }

    public Pages(int pagesize, String countfield) {
        this.pageSize = pagesize;
        this.countField = countfield == null || countfield.length() == 0 ? "*" : countfield;
        this.curPage = -1;
    }

    public Pages(int pagesize, String countfield, HttpServletRequest request) {
        this.pageSize = pagesize;
        this.countField = countfield == null || countfield.length() == 0 ? "*" : countfield;
        this.request = request;
        this.curPage = -1;
    }

    /**
     * 获取每页记录数
     *
     * @return
     */
    public int getPageSize() {
        return pageSize;
    }

    /**
     * 设置每页记录数
     *
     * @param pageSize
     */
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    /**
     * 获取分页字段
     *
     * @return
     */
    public String getCountField() {
        return countField;
    }

    /**
     * 设置分页字段
     *
     * @param countField
     */
    public void setCountField(String countField) {
        this.countField = countField;
    }

    /**
     * 获取request
     *
     * @return
     */
    public HttpServletRequest getRequest() {
        return request;
    }

    /**
     * 设置request
     *
     * @param request
     */
    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }

    /**
     * 获取当前页数
     *
     * @return
     */
    public int getCurPage() {
        return curPage;
    }

    /**
     * 设置当前页数
     *
     * @param curPage
     */
    public void setCurPage(int curPage) {
        this.curPage = curPage;
    }
}
